<template>
  <div>
    <van-nav-bar
        left-arrow
        @click-left="onClickLeft"
        title="运营商信息"
    />
    <van-form @submit="onSubmit">
      <van-field
          v-model="form.companyName"
          name="公司名称"
          label="公司名称"
          placeholder="公司名称"
          :rules="[{ required: true, message: '请填写公司名称' }]"
      />
      <van-field
          v-model="form.linkName"
          name="负责人"
          label="负责人"
          placeholder="负责人"
          :rules="[{ required: true, message: '请填写负责人' }]"
      />
      <van-field
          v-model="form.linkPhone"
          name="手机"
          label="手机"
          placeholder="手机"
          :rules="[{ required: true, message: '请填写手机号码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">保存</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {getInfo, saveInfo} from "@/api/operator";
import {getLocalOpenId} from "@/utils/wxUtil";

export default {
  data() {
    return {
      form: {
        openId: getLocalOpenId(),
        companyName: '',
        linkName: '',
        linkPhone: ''
      }
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    onSubmit: function () {
      saveInfo(this.form).then(res=>{
        this.$toast.success('保存成功');
      })
    }
  },
  mounted() {
    getInfo(this.form).then(res => {
      if (res.data) {
        this.form.companyName=res.data.companyName
        this.form.linkName=res.data.linkName
        this.form.linkPhone=res.data.linkPhone
      } else {
        this.$message.error("数据异常！")
      }
    })
  }
}
</script>

<style scoped>
</style>
